package ru.urfc.portal.ui.client.widgets;

import java.util.Iterator;

import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;

/**
 *	Make {@link FormPanel} be able append child with ui-binding  
 */
public class FormPanelWrapper extends Composite implements HasWidgets {

	interface Binder extends UiBinder<Widget, FormPanelWrapper> {}
	private static Binder binder = GWT.create(Binder.class);

	@UiField(provided = true) FormPanel formPanel = new FormPanel() {
		{
			setHeaderVisible(false);
			//setPadding(0);
		}
		@Override
		protected void onRender(com.google.gwt.user.client.Element parent, int pos) {
			super.onRender(parent, pos);
		      head.hide();
		      body.removeStyleName(bodStyle + "-noheader");
		      body.removeStyleName(baseStyle + "-body");
		};
	};
	
	public FormPanelWrapper() {
		initWidget(binder.createAndBindUi(this));		
	}
	
	public FormPanel getFormPanel() {
		return formPanel;
	}
	
	@Override
	public void add(Widget w) {
		formPanel.add(w);
	}

	@Override
	public void clear() {
		formPanel.clear();		
	}

	@Override
	public Iterator<Widget> iterator() {
		return null;
	}

	@Override
	public boolean remove(Widget w) {
		return remove(w);
	}

}
